//
//  CompereAPI.m
//  RainbowFM
//
//  Created by Kratos on 14/12/20.
//  Copyright (c) 2014年 RB. All rights reserved.
//

#import "CompereAPI.h"

#import "AFAppDotNetAPIClient.h"


@implementation CompereAPI

-(void)fetchComperesListWithUserid:(NSString *)userId
                             ucode:(NSString *)ucode
                        anchorType:(NSString *)anchorType
                          pageSize:(NSString *)pageSize
                       currentPage:(NSString *)currentPage
                            result:(void (^)(NSArray *compereList, NSString *msg))res;
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (userId) {
        [params setObject:userId forKey:@"userId"];
    }else{
        [params setObject:@"" forKey:@"userId"];
    }
    
    if (ucode) {
        [params setObject:ucode forKey:@"ucode"];
    }else{
        [params setObject:@"" forKey:@"ucode"];
    }
    
    
    if (!currentPage || !pageSize || !anchorType) {
        res(nil,@"缺少 当前页 或 每页条数 或 主持人类型");
        return;
    }else
    {
        [params setObject:anchorType forKey:@"anchorType"];
        [params setObject:currentPage forKey:@"currentPage"];
        [params setObject:pageSize forKey:@"pageSize"];
    }
    
    [[AFAppDotNetAPIClient sharedClient] POST:VIDEO_BASE_URL
                                   parameters:@{@"serviceName":@"video_anchor_list_req",
                                                @"callType":@"002",
                                                @"params":params
                                                }
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],nil);
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      }
                                      failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"erroe for fetchComperesList");
                                      }];

}

-(void)fetchCompereInfoWithUserid:(NSString *)userId
                            ucode:(NSString *)ucode
                         anchorId:(NSString *)anchorId
                           result:(void (^)(NSDictionary *compere, NSString *msg))res
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (userId) {
        [params setObject:userId forKey:@"userId"];
    }else{
        [params setObject:@"" forKey:@"userId"];
    }
    
    if (ucode) {
        [params setObject:ucode forKey:@"ucode"];
    }else{
        [params setObject:@"" forKey:@"ucode"];
    }
    
    if (!anchorId) {
        res(nil,@"缺少 主持人id");
        return;
    }else
    {
        [params setObject:anchorId forKey:@"anchorId"];
    }
    
    [[AFAppDotNetAPIClient sharedClient] POST:VIDEO_BASE_URL
                                   parameters:@{@"serviceName":@"video_anchor_detail_req",
                                                @"callType":@"002",
                                                @"params":params
                                                }
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],nil);
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      }
                                      failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"erroe for fetchCompereInfo");
                                      }];
}

-(void)addCompereWithUserid:(NSString *)userId
                       oper:(NSString *)oper
                    bhvType:(NSString *)bhvType
                   anchorId:(NSString *)anchorId
                     result:(void (^)(NSDictionary *result, NSString *msg))res
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    
    if (!userId || !anchorId || !oper) {
        res(nil,@"缺少 userid 主持人id 或 操作类型");
        return;
    }else
    {
        [params setObject:userId forKey:@"userId"];
        [params setObject:anchorId forKey:@"anchorId"];
        [params setObject:oper forKey:@"oper"];
        [params setObject:@"1" forKey:@"bhvType"];
    }
    
    [[AFAppDotNetAPIClient sharedClient] POST:VIDEO_BASE_URL
                                   parameters:@{@"serviceName":@"video_anchor_bhv_mgr_req",
                                                @"callType":@"002",
                                                @"params":params
                                                }
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],nil);
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      }
                                      failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"erroe for addCompereWithUserid");
                                      }];
}

-(void)manageLeaveWordsWithUserid:(NSString *)userId
                            ucode:(NSString *)ucode
                             oper:(NSString *)oper
                          cmtType:(NSString *)cmtType
                            cmtId:(NSString *)cmtId
                       cmtContent:(NSString *)cmtContent
                         soundUrl:(NSString *)soundUrl
                           picUrl:(NSString *)picUrl
                        cmtTarget:(NSString *)cmtTarget
                       replyCmtId:(NSString *)replyCmtId
                           result:(void (^)(NSDictionary *result, NSString *msg))res
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (!userId) {
        res(nil,@"缺少 用户ID");
        return;
    }
    
    [params setObject:userId forKey:@"userId"];
    
    if (ucode) {
        [params setObject:ucode forKey:@"ucode"];
    }else{
        [params setObject:@"" forKey:@"ucode"];
    }
    
    if (cmtId) {
        [params setObject:cmtId forKey:@"cmtId"];
    }else{
        [params setObject:@"" forKey:@"cmtId"];
    }
    
    if (replyCmtId) {
        [params setObject:replyCmtId forKey:@"replyCmtId"];
    }else{
        [params setObject:@"" forKey:@"replyCmtId"];
    }
    
    if (cmtContent) {
        [params setObject:cmtContent forKey:@"cmtContent"];
    }else{
        [params setObject:@"" forKey:@"cmtContent"];
    }
    
    if (picUrl) {
        [params setObject:picUrl forKey:@"picUrl"];
    }else{
        [params setObject:@"" forKey:@"picUrl"];
    }
    
    if (soundUrl) {
        [params setObject:soundUrl forKey:@"soundUrl"];
    }else{
        [params setObject:@"" forKey:@"soundUrl"];
    }
    
    if (!oper || !cmtType || !cmtTarget) {
        res(nil,@"缺少 操作类型 或 评论对象类型 或 评论内容 或 评论对象id");
        return;
    }else
    {
        [params setObject:oper forKey:@"oper"];
        [params setObject:cmtType forKey:@"cmtType"];
        [params setObject:cmtTarget forKey:@"cmtTarget"];
    }
    
    [[AFAppDotNetAPIClient sharedClient] POST:VIDEO_BASE_URL
                                   parameters:@{@"serviceName":@"video_cmt_mgr_req",
                                                @"callType":@"002",
                                                @"params":params
                                                }
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"],nil);
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      }
                                      failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"erroe for manageLeaveWords");
                                      }];
}

-(void)fetchLeaveWordsListWithUserid:(NSString *)userId
                               ucode:(NSString *)ucode
                             cmtType:(NSString *)cmtType
                           cmtTarget:(NSString *)cmtTarget
                             reqType:(NSString *)reqType
                            pageSize:(NSString *)pageSize
                         currentPage:(NSString *)currentPage
                              result:(void (^)(NSArray *list, NSString *msg))res
{
    NSMutableDictionary *params = [NSMutableDictionary dictionary];
    if (!userId) {
        res(nil,@"缺少 用户ID");
        return;
    }
    
    [params setObject:userId forKey:@"userId"];
    
    if (ucode) {
        [params setObject:ucode forKey:@"ucode"];
    }else{
        [params setObject:@"" forKey:@"ucode"];
    }
    
    
    if (!cmtType ||  !cmtTarget || !reqType || !pageSize || !currentPage) {
        res(nil,@"缺少 操作类型 或 评论对象ID 或 请求类型 或 请求数量 或 当前页码");
        return;
    }else
    {
        [params setObject:reqType forKey:@"reqType"];
        [params setObject:cmtTarget forKey:@"cmtTarget"];
        [params setObject:cmtType forKey:@"cmtType"];
        [params setObject:currentPage forKey:@"currentPage"];
        [params setObject:pageSize forKey:@"pageSize"];
    }
    
    [[AFAppDotNetAPIClient sharedClient] POST:VIDEO_BASE_URL
                                   parameters:@{@"serviceName":@"video_cmt_list_req",
                                                @"callType":@"002",
                                                @"params":params
                                                }
                                      success:^(NSURLSessionDataTask *task, id responseObject) {
                                          if ([responseObject[@"returnCode"] isEqualToString:@"000000"]) {
                                              res(responseObject[@"result"][@"list"],nil);
                                          }
                                          else{
                                              res(nil,responseObject[@"errorMsg"]);
                                          }
                                          
                                      }
                                      failure:^(NSURLSessionDataTask *task, NSError *error) {
                                          res(nil,@"erroe for fetchLeaveWordsList");
                                      }];
}

@end
